/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import beans.util.TravelId;
import controllers.CameraFacade;
import entities.Camera;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

/**
 *
 * @author riccardo
 */
@ManagedBean
@RequestScoped
public class FilCameraController extends AbstractController<Camera> implements Serializable {

    @Inject
    private CameraFacade ejbFacade;
    
    
    @ManagedProperty(value="#{travelId}")
    private TravelId tid; 

    public TravelId getTid() {
        return tid;
    }

    public void setTid(TravelId tid) {
        this.tid = tid;
    }

    
    public FilCameraController() {
        super(Camera.class);
        //tid.setID((String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("idViaggio"));
     
    }

    @PostConstruct
    public void init() {
        super.setFacade(ejbFacade);
    }
    
    @Override
     public List<Camera> getItems() {
        if (items == null) {
            System.out.println("buongiorno");

            String id = tid.getID();
            System.out.println("buongiorno"+id);
            if("0".equals(id) || id == null){
                items = this.ejbFacade.findAll();
            }
            else{
                items = this.ejbFacade.findByIdViaggio(Integer.parseInt(id));
            }
        }
        return items;
    }

}
